//logs.js
var util = require('../../utils/util.js')
var app = getApp();
Page({
  data: {
    logs: []
  },
  onLoad: function () {
    var that = this;
    // 消息列表
    wx.request({
      url: app.globalData.API + '/message/Applist',
      data: {
        toUserId:wx.getStorageSync('loginInfo').user.id,
        pageSize: 20,
        pageNumber: 1
      },
      method: 'POST', 
      header: {
        "Cookie":wx.getStorageSync('sessionid')
      },
      success: function(res){
        // success
        if(res.data.code == 10000){
          var meesageContent = res.data.lists.content;
          for(let i=0;i<meesageContent.length;i++){
            meesageContent[i].createTime = util.formatDate(meesageContent[i].createTime)
          }
          that.setData({
            logs:meesageContent
          })
        }
      },
      fail: function(res) {
        // fail
      },
      complete: function(res) {
        // complete
      }
    });
  },
  onPullDownRefresh: function(){//下拉刷新
    var that = this;
    wx.request({
      url: app.globalData.API + '/message/Applist',
      data: {
        toUserId:wx.getStorageSync('loginInfo').user.id,
        pageSize: 20,
        pageNumber: 1
      },
      method: 'POST', 
      header: {
        "Cookie":wx.getStorageSync('sessionid')
      },
      success: function(res){
        // success
        if(res.data.code == 10000){
          var meesageContent = res.data.lists.content;
          for(let i=0;i<meesageContent.length;i++){
            meesageContent[i].createTime = util.formatDate(meesageContent[i].createTime)
          }
          that.setData({
            logs:meesageContent
          })
        }
      },
      fail: function(res) {
        // fail
      },
      complete: function(res) {
        // complete
      }
    });
    setTimeout(function(){
            //停止刷新
            wx.stopPullDownRefresh()
          },2000)
  }
})
